/*
 * @Author: your name
 * @Date: 2021-08-12 17:10:48
 * @LastEditTime: 2021-09-03 11:06:54
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \agcim-viewer\src\views\js\net\serverData4Config.js
 */
/**
 * 支持缓冲的控制 陈彪 2020年7月2日
 */
class serverData4Config {
  /**
   * 获得后台的图层树数据
   */
  getLayerTreeData(params) {
    console.log('获取后台数据');
    return agcim.net.axiosWraper.getData(
      agcim.net.apiPath.project_getProjectLayerTree,
      params
    ); 
  }

  _saveToCache(res, code) {
    var promise = new Promise(function(accept, reject) {
      res
        .then(function(data) {
          window.sessionStorage.setItem(code, JSON.stringify(data));
          accept(data);
        })
        .catch(function(error) {
          var data = window.sessionStorage.getItem(code);
          if (!data) {
            reject();
            return;
          }
          data = JSON.parse(data);
          accept(data);
        });
    });
    return promise;
  }

  getMenuData() {}

  getFunctionData(userId) {
    //当【appSoftName】字段存在的时候，仅适用appSoftName字段作为请求参数，appSoftCode失效
    let params = {
      isTree: true,
      isAdmin: 0,
      isCloudSoft: 0,
      appSoftCode: CIM_APPLICATION_NAME,
      appSoftName: CIM_APPLICATION_NAME,
    };

    var url = agcim.net.apiPath.func_findFuncByUser+`/` + userId;
    let res = agcim.net.axiosWraper.getData(url, params);
    return this._saveToCache(res, "functions_097285");
  }
  /**
   *
   * @param {*} codeName
   * @memberof serverData4Config
   */
  getWidgetByProjectName(codeName){
    let url = agcim.net.apiPath.func_findFuncByUser
    let params = {
      code:codeName
    }
    return agcim.net.axiosWraper.getData(url, params);
  }

  getViewPointData() {}

  getRoamData() {}

  saveViewPointData() {}

  saveRoamData() {}

  getKeyValueData() {}

  saveKeyValueData() {}

  getJsonData() {}

  saveJsonData() {}
}
export default new serverData4Config();
